/* C.Isatty: Test a stream to check whether it is 'interactive' */

#include <stdio.h>
#include "kernel.h"

#define fileno(fp) ((int *)fp)[5]

int isatty (FILE *fp)
{
	_kernel_swi_regs r;

	/* If fp == NULL, say non-interactive... */
	if (fp == NULL)
		return 0;

	/* If we cannot seek on fp, the file is probably (?) a terminal,
	 * and so interactive.
	 */
	if (fseek (fp, 0, SEEK_CUR) != 0)
		return 1;

	/* We can seek, so we are a normal file. Does the OS think
	 * that fp is interactive?
	 */
	r.r[0] = 254;
	r.r[1] = fileno(fp);
	_kernel_swi(0x09,&r,&r);

	return ((r.r[0] & 8) == 8);
}
